<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="MASM 6.11编程系统对宏定义及其相关语句进行了一定程度的扩充。虽然这些扩充给编程带来了一些方便，但它们不一定能被其它的汇编语言编程系统所接受，所以，程序员在使用这些方便的扩充功能时，要注意到可能带来的限制。 下面介绍MASM 6.11编程系统对宏及其相关语句的扩充。  9.6.1 宏定义形式在MASM 6.11编程系统中，其宏定义的一般形式如下： 1234567891011宏名 MACRO?">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="9.6 宏的扩充">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/04/01/asm42/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="MASM 6.11编程系统对宏定义及其相关语句进行了一定程度的扩充。虽然这些扩充给编程带来了一些方便，但它们不一定能被其它的汇编语言编程系统所接受，所以，程序员在使用这些方便的扩充功能时，要注意到可能带来的限制。 下面介绍MASM 6.11编程系统对宏及其相关语句的扩充。  9.6.1 宏定义形式在MASM 6.11编程系统中，其宏定义的一般形式如下： 1234567891011宏名 MACRO?">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-01-22T09:26:41.302Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="9.6 宏的扩充">
<meta name="twitter:description" content="MASM 6.11编程系统对宏定义及其相关语句进行了一定程度的扩充。虽然这些扩充给编程带来了一些方便，但它们不一定能被其它的汇编语言编程系统所接受，所以，程序员在使用这些方便的扩充功能时，要注意到可能带来的限制。 下面介绍MASM 6.11编程系统对宏及其相关语句的扩充。  9.6.1 宏定义形式在MASM 6.11编程系统中，其宏定义的一般形式如下： 1234567891011宏名 MACRO?">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/04/01/asm42/">





  <title>9.6 宏的扩充 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/04/01/asm42/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">9.6 宏的扩充</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-04-01T20:36:07+08:00">
                2015-04-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/汇编教程/" itemprop="url" rel="index">
                    <span itemprop="name">汇编教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>MASM 6.11编程系统对宏定义及其相关语句进行了一定程度的扩充。虽然这些扩充给编程带来了一些方便，但它们不一定能被其它的汇编语言编程系统所接受，所以，程序员在使用这些方便的扩充功能时，要注意到可能带来的限制。</p>
<p>下面介绍MASM 6.11编程系统对宏及其相关语句的扩充。</p>
<hr>
<h2 id="9-6-1-宏定义形式"><a href="#9-6-1-宏定义形式" class="headerlink" title="9.6.1 宏定义形式"></a>9.6.1 宏定义形式</h2><p>在MASM 6.11编程系统中，其宏定义的一般形式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">宏名 MACRO?[参数1[:tag]] [，参数2[:tag]...]</span><br><span class="line"></span><br><span class="line">[LOCAL varlist]</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">[EXITM [value]]</span><br><span class="line"></span><br><span class="line">ENDM ;宏定义体内的局部变量和标号 </span><br><span class="line"></span><br><span class="line">;宏的定义体</span><br></pre></td></tr></table></figure>
<p>对上述宏定义的说明与9.1.1节中的说明完全一致，其需要增加的说明如下：</p>
<table border="0" cellspacing="0" cellpadding="0"><tr><td>tag——&nbsp;</td><td>其值可以是REQ、=&lt;缺省值&gt;或VARARG</td></tr><tr><td><p align="right"></p></td><td><p> </p><table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td>REQ</td><td>指定该参数是不可缺少。在宏引用时，若该参数不对应某个“实参”，那么，汇编程序会报错； </td></tr><tr><td>=&lt;缺省值&gt;</td><td>在宏引用时，若不指定该参数所对应的“实参”，那么，该参数就取其缺省值； </td></tr><tr><td valign="top">VARARG</td><td>该参数对应一个可变长的实参表，各实参之间用逗号分开；若参数的属性指定为VARARG，那么，该参数一定要是最后一个参数。 有关该属性的应用，请见随后9.6.7节中的举例。 </td></tr></tbody></table></td></tr><tr><td>value——</td><td>&nbsp;宏功能的返回值，其为可选项。 </td></tr></table>

<h2 id="9-6-2-重复伪指令REPEAT"><a href="#9-6-2-重复伪指令REPEAT" class="headerlink" title="9.6.2 重复伪指令REPEAT"></a>9.6.2 重复伪指令REPEAT</h2><p>重复伪指令REPEAT与前面9.4.1节中伪指令REPT在功能和使用方式方面完全一致，设置该伪指令的主要原因是保证与先前版本的兼容性。</p>
<p>伪指令REPEAT的使用方式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">REPEAT 数值表达式 </span><br><span class="line"></span><br><span class="line">语句序列 ;被重复的汇编语言语句 </span><br><span class="line"></span><br><span class="line">ENDM</span><br></pre></td></tr></table></figure>
<h2 id="9-6-3-循环伪指令WHILE"><a href="#9-6-3-循环伪指令WHILE" class="headerlink" title="9.6.3 循环伪指令WHILE"></a>9.6.3 循环伪指令WHILE</h2><p>循环伪指令WHILE的使用方式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> WHILE Exp</span><br><span class="line">语句序列 ;被重复的汇编语言语句</span><br><span class="line"></span><br><span class="line"> ENDM</span><br></pre></td></tr></table></figure>
<p>其功能是先判断表达式Exp是否为假(或为0)，若是，则终止该伪指令的功能，否则，循环汇编下面的指令块。表达式Exp是能在汇编时计算出其值的数值表达式。</p>
<p><strong>例9.16：编写一个带有参数result和k的宏，其功能是把1+2+…+k的累加和存入result之中，其中：result是不可缺省的，k的缺省值为1。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">SUM MACRO　result:REQ, k:=&lt;1&gt;</span><br><span class="line"></span><br><span class="line">LOCAL　n</span><br><span class="line"></span><br><span class="line">n = k</span><br><span class="line"></span><br><span class="line">mov result, 0</span><br><span class="line"></span><br><span class="line">WHILE n</span><br><span class="line"></span><br><span class="line">add?result, n</span><br><span class="line"></span><br><span class="line">n = n - 1</span><br><span class="line"></span><br><span class="line">ENDM</span><br><span class="line"></span><br><span class="line">ENDM</span><br></pre></td></tr></table></figure>
<p>有了上面的宏定义，就可书写下面的宏引用来实现其相应的功能：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">SUM ax, 10 ;寄存器ax=1+2+3+…+10</span><br><span class="line"></span><br><span class="line">SUM bh ;寄存器bh=1，因为第二个形参取其缺省值 </span><br><span class="line"></span><br><span class="line">SUM ecx, 100? ;寄存器ecx=1+2+3+…+100</span><br><span class="line"></span><br><span class="line">SUM data, 20 ;存储单元data=1+2+3+…+20</span><br><span class="line">``` </span><br><span class="line"></span><br><span class="line">## 9.6.4 循环伪指令FOR</span><br><span class="line"></span><br><span class="line">循环伪指令FOR与9.4.2节中伪指令IRP在功能上完全一致，设置该伪指令的原因也是为了保证与先前版本的兼容性。</span><br><span class="line"></span><br><span class="line">伪指令FOR的使用方式如下：</span><br></pre></td></tr></table></figure>
<p> FOR　 parameter[:REQ|:=<default>],  <argument [, argument]...><br>语句序列 ;被重复的汇编语言语句<br>ENDM<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">其中各参数的说明如下：</span><br><span class="line"></span><br><span class="line">- **parameter** 一个合法的标识符，它依次取后面参数表中的值。在指令序列中，该变量的每次出现都用其值所替换；</span><br><span class="line"></span><br><span class="line">- **:REQ** 说明该变量的取值不能为空；</span><br><span class="line"></span><br><span class="line">- **:=&amp;lt;default&amp;gt;** 指定该变量的缺省值，若后面的参数表缺省某个参数(用连续的逗号)，这时，该循环变量将取其缺省值；</span><br><span class="line"></span><br><span class="line">- **Argument** 参数表中可含有文本、符号、字符串或数值常量，每个参数之间要用逗号分割。</span><br><span class="line"></span><br><span class="line">例如：</span><br></pre></td></tr></table></figure></argument></default></p>
<p>FOR data:=&lt; ?&gt;, &lt;”123”, , 21, 0&gt;</p>
<p>DB　data</p>
<p>ENDM</p>
<p>……</p>
<p>FOR reg:REQ, &lt; ax, bx, dx&gt;</p>
<p>push　reg</p>
<p>ENDM<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">该语句在宏展开时，将得到下列语句：</span><br></pre></td></tr></table></figure></p>
<p>DB　“123”<br>DB　?<br>DB　21<br>DB　0<br>……<br>push　ax<br>push　bx<br>push　dx<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 9.6.5 循环伪指令FORC</span><br><span class="line"></span><br><span class="line">循环伪指令FOR与9.4.3节中伪指令IRPC在功能上完全一致，它也是为保证与先前版本的兼容性而设置的。</span><br><span class="line"></span><br><span class="line">伪指令FORC的使用方式如下：</span><br></pre></td></tr></table></figure></p>
<p>FORC parameter, </p>
<p>语句序列 ;被重复的汇编语言语句 </p>
<p>ENDM<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">其中各参数的说明如下：</span><br><span class="line"></span><br><span class="line">- **parameter**： 一个合法的标识符，它依次取字符串中的每个字符。在语句序列中，该变量的每次出现都用其值所替换；</span><br><span class="line"></span><br><span class="line">- **String**： 一个字符串或被定义为字符串的符号名，字符串中的空格也被算为一个字符。括号&quot;&lt;&quot;、&quot;&gt;&quot;是必不可少的。</span><br><span class="line"></span><br><span class="line">例如：</span><br></pre></td></tr></table></figure></p>
<p>FORC data, &lt;1?3&gt;<br>DB　data<br>ENDM<br>……<br>FORC reg,<br>push　reg&amp;x<br>ENDM<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">该语句在宏展开时，将得到下列语句：</span><br></pre></td></tr></table></figure></p>
<p>DB　1</p>
<p>DB　?</p>
<p>DB　3</p>
<p>……</p>
<p>push　ax</p>
<p>push　bx</p>
<p>push　dx<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 9.6.6 转移伪指令GOTO</span><br><span class="line"></span><br><span class="line">转移伪指令GOTO用于实现宏定义体内的转移功能，其使用方式如下：</span><br></pre></td></tr></table></figure></p>
<p>GOTO　标号 </p>
<p>…</p>
<p>:标号　;标号后不能写指令，但可写注释 </p>
<p>…<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">该伪指令的功能是使汇编程序转移到“标号”处汇编，它只能在宏定义MACRO、REPEAT、WHILE、FOR和FORC等语句块内使用，该标号也只在该语句块内有效。</span><br><span class="line"></span><br><span class="line">## 9.6.7 宏扩充的举例</span><br><span class="line"></span><br><span class="line">例9.17：编写一个给任意寄存器或存储单元清零的宏定义。</span><br><span class="line"></span><br><span class="line">解：</span><br></pre></td></tr></table></figure></p>
<p>Clear list : VARARG</p>
<p>FOR data:REQ,<br>mov　data, 0<br>ENDM<br>ENDM<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">有了上面的宏定义，下面的二个宏引用都是正确的，尽管宏引用时所带的参数个数是不同的。这正是参数属性VARARG的作用所在。</span><br></pre></td></tr></table></figure></p>
<p>Clear?ax, bx</p>
<p>……</p>
<p>Clear?si, cl, MemVar, edx　;MemVar是内存变量，任意类型都可以<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">这二个宏引用展开时所得到的指令如下：</span><br></pre></td></tr></table></figure></p>
<p>mov　ax, 0</p>
<p>mov　bx, 0</p>
<p>……</p>
<p>mov　si, 0</p>
<p>mov　cl, 0</p>
<p>mov　MemVar, 0</p>
<p>mov　edx, 0<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 9.6.8 系统定义的宏</span><br><span class="line"></span><br><span class="line">MASM 6.11系统定义了大量的标准宏，程序员能很方便地使用它们。在使用这些系统宏之前，要象C语言那样用伪指令INCLUDE把有关“宏库”文件包含在用户的源程序中。主要的系统宏库文件有：DOS.INC和BIOS.INC，它们存放在系统的include子目录中。</span><br><span class="line"></span><br><span class="line">**例9.18：使用系统宏定义，编写从键盘上读取一个字符。**</span><br><span class="line"></span><br><span class="line">解：</span><br></pre></td></tr></table></figure></p>
<p>include dos.inc　;把系统宏定义文件包含在源程序之中 </p>
<p>……</p>
<p>@getchar 1, 1　;引用系统宏定义 </p>
<p>……<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">下面是系统宏@getchar的使用参数描述和定义，其它系统宏的有关信息请参阅相关的宏定义文件。</span><br><span class="line"></span><br><span class="line">### 1、系统宏@GetChar的使用说明</span><br><span class="line"></span><br><span class="line">宏的功能： 从键盘读字符</span><br><span class="line"></span><br><span class="line">使用语法：</span><br></pre></td></tr></table></figure></p>
<p> @GetChar  [echo] [，[break] [，clearbuf]]<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">参数说明： </span><br><span class="line"></span><br><span class="line">- &amp;lt;echo&amp;gt; ;常量，非零表示“回显”，缺省值为“回显”</span><br><span class="line"></span><br><span class="line">- &amp;lt;break&amp;gt; ;常量，非零表示接受“^C”，缺省值为“接受”</span><br><span class="line"></span><br><span class="line">- &amp;lt;clearbuf&amp;gt; ;常量，非零表示清键盘缓冲区，缺省值为“不清”</span><br><span class="line"></span><br><span class="line">返回参数： AL＝ASCII码</span><br><span class="line"></span><br><span class="line">内容破坏： AX，DL(若回显，且不接受^C)</span><br><span class="line"></span><br><span class="line">参见内容： INT 21h — 01h、07h、08h和0Ch，@GetStr</span><br><span class="line"></span><br><span class="line">### 2、系统宏@GetChar的定义</span><br><span class="line"></span><br><span class="line">该宏定义在宏库文件dos.inc中，其具体宏定义如下：</span><br></pre></td></tr></table></figure></p>
<p>@GetChar MACRO　ech:=<1>, cc:=<1>, clear:=<0></0></1></1></p>
<p>LOCAL　funct, disp</p>
<p>disp = 1</p>
<p>IF ech</p>
<p>IF cc</p>
<p>funct = 01h　;使用功能1</p>
<p>ELSE</p>
<p>funct = 07h　;使用功能7</p>
<p>disp = 02h　;设置需要回显标志 </p>
<p>ENDIF</p>
<p>ELSE</p>
<p>IF cc</p>
<p>funct = 08h　;使用功能8</p>
<p>ELSE</p>
<p>funct = 07h　;使用功能7</p>
<p>ENDIF</p>
<p>ENDIF</p>
<p>IFE clear</p>
<p>mov　ah, funct　;置功能号 </p>
<p>ELSE</p>
<p>mov　ah, 0Ch　;先清输入缓冲区，再接受键盘输入 </p>
<p>mov　al, funct</p>
<p>ENDIF</p>
<p>Int　21h　;调用DOS功能中断 </p>
<p>IF disp EQ 02h　;检查是否需要回显 </p>
<p>mov　dl, al</p>
<p>mov　ah, 02h</p>
<p>int　21h</p>
<p>ENDIF</p>
<p>ENDM<br><code>`</code></p>
<p>对于上面的宏定义，程序员完全可以把它修改成其它形式的宏定义。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/04/01/asm41/" rel="next" title="9.5 条件汇编伪指令">
                <i class="fa fa-chevron-left"></i> 9.5 条件汇编伪指令
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/04/01/asm43/" rel="prev" title="10.1 字符串的处理程序">
                10.1 字符串的处理程序 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#9-6-1-宏定义形式"><span class="nav-number">1.</span> <span class="nav-text">9.6.1 宏定义形式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-6-2-重复伪指令REPEAT"><span class="nav-number">2.</span> <span class="nav-text">9.6.2 重复伪指令REPEAT</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-6-3-循环伪指令WHILE"><span class="nav-number">3.</span> <span class="nav-text">9.6.3 循环伪指令WHILE</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
